﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Controls_News : System.Web.UI.UserControl
{
    string strSQL;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            newsbig();
            newsli();
            //newsx();
        }
    }
    public void newsbig()
    {
        strSQL = "select top 8 * from News_Big  order by Sort desc";
        IDataReader dr = Class1.GetDataReader(strSQL);
        while (dr.Read())
        {
            news_big.Text += "<a href='wjNews_Class_" + dr["Big_Id"] + ".html'>" + dr["News_Big"].ToString().Trim() + "</a>&nbsp;┆&nbsp;";
        }
    }
    //public void newsx()
    //{

    //    DataTable dt = Class1.ExecSel("select top 1 n_ID, case when len(n_Title)>20 then left(n_Title,20)+'...' else n_Title end as n_Title,n_Content,n_Lock,n_HomeShow from News where n_Lock=0 and n_HomeShow=1 order by n_ID desc");
    //    news.Text = "<a href='wjNews_View_" + dt.Rows[0]["n_ID"] + ".html'>" + dt.Rows[0]["n_Title"].ToString().Trim() + "</a>";

    //    if (dt.Rows[0]["n_Content"].ToString().Length > 30)
    //    {
    //        string str = dt.Rows[0]["n_Content"].ToString();
    //        str = str.Replace("<BR>", "");
    //        str = str.Replace("&nbsp;", "");

    //        news_body.Text = "<a href='wjNews_View_" + dt.Rows[0]["n_ID"] + ".html'>" + str.Substring(0, 30).Trim() + "..." + "</a>";
    //    }
    //}
    public void newsli()
    {
        strSQL = "select top 18 * from News inner join News_Big on News.n_Big_ID = News_Big.Big_Id where n_Lock=0 and n_HomeShow=1 order by n_ID desc";
        SqlConnection conn =Class1.DBconnection();
        SqlDataAdapter da = new SqlDataAdapter(strSQL, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataTable dt = ds.Tables[0];
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            if (ds.Tables[0].Rows[i]["n_Title"].ToString().Length > 13)
            {
                ds.Tables[0].Rows[i]["n_Title"] = ds.Tables[0].Rows[i]["n_Title"].ToString().Substring(0, 13).Trim() + "";
            }
            if (ds.Tables[0].Rows[i]["News_Big"].ToString().Length > 2)
            {
                ds.Tables[0].Rows[i]["News_Big"] = ds.Tables[0].Rows[i]["News_Big"].ToString().Substring(0, 2).Trim() + "";
            }
        }
        if (dt.Rows.Count > 0)
        {
            dl_news.DataSource = ds.Tables[0];
            dl_news.DataBind();
        }
        conn.Close();
        conn.Dispose();
        da.Dispose();
        ds.Dispose();
    }
}
